#pragma tabsize 0
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <left4dhooks>
#define PLUGIN_VERSION "1.0"

ConVar g_smoker_yy, g_smoker_zz, g_smoker_qqq;
float h_smoker_yy, h_smoker_zz;
int h_smoker_qqq;


public Plugin myinfo =
{
	name = "l4d2_special_feeling_jump",
	author = "豆瓣酱な",
	description = "特感近战攻击，击飞玩家",
	version = PLUGIN_VERSION,
	url = "https://gitee.com/sweet-and-sour-bombs/adfvsdsd"
};


public void OnPluginStart()
{

	g_smoker_qqq = CreateConVar("smoker_xxy_jump", "1", "是否启用插件?", FCVAR_NOTIFY, true, 0.0, true, 1.0);
	g_smoker_yy = CreateConVar("smoker_yx_jump", "100.0", "玩家Y轴高度.", FCVAR_NOTIFY, true, 0.0);
	g_smoker_zz = CreateConVar("smoker_zx_jump", "251.0",   "玩家Z轴击飞高度.", FCVAR_NOTIFY, true, 0.0);
	CreateConVar("l4d2_smokxxer_attacker_jump_version", PLUGIN_VERSION, "插件版本.", FCVAR_NOTIFY);

	HookConVarChange(g_smoker_qqq, eConvarChanged);
	HookConVarChange(g_smoker_yy, eConvarChanged);
	HookConVarChange(g_smoker_zz, eConvarChanged);

	HookEvent("player_hurt",			        Event_PlayerHurt, 			EventHookMode_Pre);  //玩家受伤事件
	HookEvent("player_incapacitated",			Event_PlayerHurt, 	        EventHookMode_Pre);  //玩家倒地事件


	//AutoExecConfig(true, "l4d2_special_feeling_jump");
}


public void OnMapStart()
{
	CvarsChanged();
}

public void eConvarChanged(Handle hCvar, const char[] sOldVal, const char[] sNewVal)
{
	CvarsChanged();
}

void CvarsChanged()
{
	h_smoker_qqq = g_smoker_qqq.IntValue;
	h_smoker_yy = g_smoker_yy.FloatValue;
	h_smoker_zz = g_smoker_zz.FloatValue;

}


//玩家受伤事件.
public void Event_PlayerHurt(Event event, const char[] name, bool dontBroadcast)
{
	if(h_smoker_qqq == 0)
		return;
		


	int victim = GetClientOfUserId(event.GetInt("userid"));
	int attacker = GetClientOfUserId(event.GetInt("attacker"));
	
	if(IsClientPinned(victim))
	return;	
	
	char WeaponUsed[256];
	GetEventString(event, "weapon", WeaponUsed, sizeof(WeaponUsed));

	if (IsValidClient(victim) && IsPlayerAlive(victim) && GetClientTeam(victim) == 2 )
	{
		if(StrEqual(WeaponUsed, "charger_claw") 
		|| StrEqual(WeaponUsed, "spitter_claw") 
		|| StrEqual(WeaponUsed, "smoker_claw") 
		|| StrEqual(WeaponUsed, "jockey_claw") 
		|| StrEqual(WeaponUsed, "hunter_claw")  
		|| StrEqual(WeaponUsed, "tank_claw") 
		|| StrEqual(WeaponUsed, "tank_rock")
		|| StrEqual(WeaponUsed, "boomer_claw"))		
		{

			L4D2_Circle(victim, attacker);
			
		}
	}


}





public void L4D2_Circle(int victim, int attacker)
{
    if (IsValidClient(victim) && GetClientTeam(victim) == 2)
	{
				float HeadingVector[3], resulting[3], fPos[3];
				GetClientEyeAngles(attacker, HeadingVector);
				GetEntPropVector(victim, Prop_Data, "m_vecVelocity", resulting);

				resulting[0] += Cosine(DegToRad(HeadingVector[1])) * h_smoker_yy;
				resulting[1] += Sine(DegToRad(HeadingVector[1])) * h_smoker_yy;
				resulting[2] =  h_smoker_zz;
				TeleportEntity(victim, NULL_VECTOR, NULL_VECTOR, resulting);
				GetClientAbsOrigin(attacker, fPos);
				L4D_StaggerPlayer(victim, attacker, fPos); // 踉跄  效果
				L4D2_CTerrorPlayer_Fling(victim, attacker, resulting);
	}
}


//判断玩家是否被控
bool IsClientPinned(int client)
{
	if (GetEntPropEnt(client, Prop_Send, "m_pummelAttacker") > 0)
		return true;
	if (GetEntPropEnt(client, Prop_Send, "m_carryAttacker") > 0)
		return true;
	if (GetEntPropEnt(client, Prop_Send, "m_pounceAttacker") > 0)
		return true;
	if (GetEntPropEnt(client, Prop_Send, "m_jockeyAttacker") > 0)
		return true;
	if (GetEntPropEnt(client, Prop_Send, "m_tongueOwner") > 0)
		return true;
	return false;
}


//判断是否有效玩家
bool IsValidClient(int client)
{
	return client > 0 && client <= MaxClients && IsClientInGame(client);
}



